package code.structure.manager.language 
{
	import flash.utils.Dictionary;
	
	/**
	 * 语言名包文件
	 * @author CYang
	 * @date   2011-9-19 11:23
	 */
	public class LanguageManager 
	{
		private static var _xmlLanuage:XML;
		private static var languageDic:Dictionary;
		public function LanguageManager()
		{
			
		}
		/**
		 * 获取语言信息
		 * @param	key
		 * @param	params 需要替换的参数
		 */
		public static function getLanguageInfo(key:String, params:Array = null):String
		{
			var lab:String = "";
			if(languageDic && languageDic[key]){
				lab = languageDic[key] || "";
				if (params && lab != "") {
					for (var i:int = 0; i < params.length; i++) {
						lab = lab.replace("{" + i + "}", params[i]);
					}
				}
			}
			
			return lab;
		}
		
		public static function set xmlLanuage(value:XML):void{
			_xmlLanuage = value;
			analyLanuageXML();
		}
		
		/**
		 *解析多语言表 
		 * 
		 */
		private static function analyLanuageXML():void{
			if(!_xmlLanuage) return;
			languageDic = new Dictionary();
			var count:int = _xmlLanuage.info.length();
			for(var i:int=0;i<count;i++){
				var content:String = _xmlLanuage.info[i].toString();
				var myPattern:RegExp = /\\n/gi;
//				content = content.replace(myPattern, "<br>");
				content = content.replace(myPattern, "\n");
				languageDic[_xmlLanuage.info[i].@name.toString()] = content;
			}
		}

	}

}